/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.settlement;

import com.xtd.model.employment.Employee;
import com.xtd.util.PostingTypeEnum;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "posting")
@NamedQueries({
    @NamedQuery(name = "Posting.findAll", query = "SELECT p FROM Posting p")})
public class Posting implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(name = "paymentMethod")
    private String paymentMethod;
    @Column(name = "amount")
    private BigDecimal amount;
    @Column(name = "createdTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdTime;
    @JoinColumn(name = "createdBy", referencedColumnName = "id")
    @ManyToOne
    private Employee createdBy;
    @Column(name = "type")
    @Enumerated(EnumType.STRING)
    private PostingTypeEnum type;
    @JoinColumn(name = "form_id", referencedColumnName = "id")
    @ManyToOne
    private Form form;
    @JoinColumn(name = "handler", referencedColumnName = "id")
    @ManyToOne
    private Employee handler;

    public Posting() {
    }

    public Posting(Form form, PostingTypeEnum type, Employee createdBy) {
        this.form = form;
        this.type = type;
        createdTime = new Date();
        this.createdBy = createdBy;
        this.handler = createdBy;

    }

    public Posting(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public Employee getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Employee createdBy) {
        this.createdBy = createdBy;
    }

    public PostingTypeEnum getType() {
        return type;
    }

    public void setType(PostingTypeEnum type) {
        this.type = type;
    }

    public Form getForm() {
        return form;
    }

    public void setForm(Form form) {
        this.form = form;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Posting)) {
            return false;
        }
        Posting other = (Posting) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.xtd.model.Posting[id=" + id + "]";
    }

    /**
     * @return the handler
     */
    public Employee getHandler() {
        return handler;
    }

    /**
     * @param handler the handler to set
     */
    public void setHandler(Employee handler) {
        this.handler = handler;
    }
}
